package testbservicecontroller.controller;


import com.hzh.api.dto.BDto;
import com.hzh.api.service.BService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/b")
public class BController {

    private static final Logger log = LoggerFactory.getLogger(BController.class);
    @DubboReference
    private BService bService;

    @GetMapping("/hello")
    public String hello() {
        MDC.put("traceId", "ACD-asa");  // 设置 traceId
        MDC.put("userId", "user123");    // 设置 userId
        log.error("hello error log");
        return "Hello from BController";
    }

    @GetMapping("/dubbo")
    public String helloDubbo() {
        BDto bDto = new BDto();
        log.error("dubbo error log");
        bDto.setName("xxx BController->BService");
        return bService.testB(bDto);
    }

    @GetMapping("/ex")
    public String ex() {
        try{
            bService.testException();
            return "正常";
        }catch (Exception e){
            return "捕抓到 "+e.getMessage();
        }
    }
}
